退出session时不再反初始化相机

chengzhenyu 7 years ago
parent
commit
b4ba40a67a

+ 25 - 6
app/src/main/java/ai/pai/lensman/dslr/CameraService.java

@@ -38,6 +38,7 @@ public class CameraService extends Service {
38 38
     public static final int CMD_INIT_CAMERA_CONNECTION = 9000;
39 39
     public static final int CMD_EXIT_CAMERA_CONNECTION = 9001;
40 40
     public static final int CMD_START_CAPTURE_PHOTO = 9002;
41
+    public static final int CMD_STOP_CAPTURE_PHOTO = 9003;
41 42
 
42 43
     private static final String MSG_TYPE_CAMERA_ERROR = "camero error";//相机错误,可能是线松动了。先exit,然后重新init
43 44
     private static final String MSG_TYPE_NOT_INIT = "not init";  //需要初始化
@@ -62,10 +63,15 @@ public class CameraService extends Service {
62 63
                 stopCameraService();
63 64
             }else if(cmd == CMD_INIT_CAMERA_CONNECTION){
64 65
                 if(!isInitExecuted){
65
-                    LogHelper.d("czy","CameraService 收到重启进程任务");
66
+                    LogHelper.d("czy","CameraService 收到初始化相机任务");
66 67
                     count = 0;
67 68
                     cameraInitTask = new CameraInitTask();
68 69
                     cameraInitTask.execute();
70
+                }else{
71
+                    LogHelper.d("czy","CameraService 相机初始化成功");
72
+                    Bundle bundle = new Bundle();
73
+                    bundle.putInt(EXTRA_STATUS_PART,MSG_CAMERA_INIT_SUCCESS);
74
+                    sendCameraIntent(bundle);
69 75
                 }
70 76
             }else if(cmd == CMD_START_CAPTURE_PHOTO){
71 77
                 if(isInitExecuted){
@@ -75,6 +81,15 @@ public class CameraService extends Service {
75 81
                         startCapture();
76 82
                     }
77 83
                 }
84
+            }else if(cmd == CMD_STOP_CAPTURE_PHOTO){
85
+               stopCapture();
86
+            }
87
+        }else{
88
+            if(!isInitExecuted){
89
+                LogHelper.d("czy","CameraService自动重启,初始化相机");
90
+                count = 0;
91
+                cameraInitTask = new CameraInitTask();
92
+                cameraInitTask.execute();
78 93
             }
79 94
         }
80 95
         return super.onStartCommand(intent, flags, startId);
@@ -112,7 +127,6 @@ public class CameraService extends Service {
112 127
         @Override
113 128
         protected Integer doInBackground(Void... params) {
114 129
             LogHelper.d("czy","CameraService CameraInitTask  ");
115
-            isInitExecuted = true;
116 130
              return  CameraJNIInterface.getInstance().java_mygpcamerainit();
117 131
         }
118 132
 
@@ -124,6 +138,7 @@ public class CameraService extends Service {
124 138
             }
125 139
             if(result>=0){
126 140
                 LogHelper.d("czy","CameraService 相机初始化成功");
141
+                isInitExecuted = true;
127 142
                 Bundle bundle = new Bundle();
128 143
                 bundle.putInt(EXTRA_STATUS_PART,MSG_CAMERA_INIT_SUCCESS);
129 144
                 sendCameraIntent(bundle);
@@ -147,10 +162,7 @@ public class CameraService extends Service {
147 162
 
148 163
     }
149 164
     public void startCapture() {
150
-        if(photoCaptureTimer !=null){
151
-            photoCaptureTimer.cancel();
152
-            photoCaptureTimer = null;
153
-        }
165
+        stopCapture();
154 166
         photoCaptureTimer = new Timer();
155 167
         photoCaptureTimer.schedule(new TimerTask() {
156 168
             @Override
@@ -160,6 +172,13 @@ public class CameraService extends Service {
160 172
         },1000,10);
161 173
     }
162 174
 
175
+    public void stopCapture(){
176
+        if(photoCaptureTimer !=null){
177
+            photoCaptureTimer.cancel();
178
+            photoCaptureTimer = null;
179
+        }
180
+    }
181
+
163 182
     private void fetchPhotoTask(){
164 183
         if(!isLastQueryReturned){
165 184
             LogHelper.d("czy","CameraService fetchPhotoTask last query not finished,return ");

+ 2 - 1
app/src/main/java/ai/pai/lensman/session/SessionInteractor.java

@@ -22,6 +22,7 @@ import static ai.pai.lensman.dslr.CameraService.ACTION_CAMERA_SERVICE_STATUS_CHA
22 22
 import static ai.pai.lensman.dslr.CameraService.CMD_EXIT_CAMERA_CONNECTION;
23 23
 import static ai.pai.lensman.dslr.CameraService.CMD_INIT_CAMERA_CONNECTION;
24 24
 import static ai.pai.lensman.dslr.CameraService.CMD_START_CAPTURE_PHOTO;
25
+import static ai.pai.lensman.dslr.CameraService.CMD_STOP_CAPTURE_PHOTO;
25 26
 import static ai.pai.lensman.dslr.CameraService.EXTRA_CMD;
26 27
 import static ai.pai.lensman.dslr.CameraService.EXTRA_DATA_PART;
27 28
 import static ai.pai.lensman.dslr.CameraService.EXTRA_SESSION_DIR;
@@ -93,7 +94,7 @@ public class SessionInteractor implements Callback{
93 94
             mHandler = null;
94 95
         }
95 96
         Intent intent = new Intent(App.getAppContext(), CameraService.class);
96
-        intent.putExtra(EXTRA_CMD,CMD_EXIT_CAMERA_CONNECTION);
97
+        intent.putExtra(EXTRA_CMD,CMD_STOP_CAPTURE_PHOTO);
97 98
         App.getAppContext().startService(intent);
98 99
         try{
99 100
             App.getAppContext().unregisterReceiver(cameraReceiver);